package com.lg.partition15;

import java.io.*;
import java.util.PriorityQueue;

/**
 * @author `RKC`
 * @date 2022/4/13 9:01
 */
public class P1462通往奥格瑞玛的道路 {

    private static final int N = 10010, M = 100010, INF = 0x3f3f3f3f;
    private static int[] h = new int[N], e = new int[M], ne = new int[M], hw = new int[N], w = new int[M];
    private static int[] dist = new int[N];
    private static PriorityQueue<Node> heap = new PriorityQueue<>(N);
    private static int n, m, k, idx = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        k = Integer.parseInt(ss[2]);
        for (int i = 1; i <= n; i++) h[i] = -1;
        int l = INF, r = -INF;
        for (int i = 1; i <= n; i++) {
            hw[i] = Integer.parseInt(reader.readLine());
            l = Math.min(l, hw[i]);
            r = Math.max(r, hw[i]);
        }
        for (int i = 1; i <= m; i++) {
            ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]), c = Integer.parseInt(ss[2]);
            add(a, b, c);
            add(b, a, c);
        }
        //二分答案，要求最大值最小
        while (l < r) {
            int mid = l + r >> 1;
            if (check(mid)) r = mid;
            else l = mid + 1;
        }
        //最后check一遍
        if (check(l)) writer.write(l + "\n");
        else writer.write("AFK\n");
        writer.flush();
    }

    private static boolean check(int limit) {
        if (hw[1] > limit || hw[n] > limit) return false;
        for (int i = 1; i <= n; i++) dist[i] = INF;
        dist[1] = 0;
        heap.clear();
        heap.add(new Node(1, 0));
        while (!heap.isEmpty()) {
            int u = heap.poll().u;
            if (u == n) return true;
            for (int i = h[u]; i != -1; i = ne[i]) {
                int v = e[i];
                if (dist[v] > dist[u] + w[i] && hw[v] <= limit && dist[u] + w[i] <= k) {
                    dist[v] = dist[u] + w[i];
                    heap.add(new Node(v, dist[v]));
                }
            }
        }
        return false;
    }

    private static void add(int a, int b, int c) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx;
        w[idx++] = c;
    }

    private static class Node implements Comparable<Node> {
        private int u;
        private long d;

        public Node(int u, long d) {
            this.u = u;
            this.d = d;
        }

        @Override
        public int compareTo(Node o) {
            return Long.compare(d, o.d);
        }
    }
}
